import {Component, OnInit} from '@angular/core';
import {BasePage} from '../../common/basePage';
import {ModalController, NavController, PopoverController, ToastController} from '@ionic/angular';
import {HttpService} from '../../services/http.service';
import {ActivatedRoute} from '@angular/router';
import {BidItemComponent} from '../../components/bid-item/bid-item.component';
import {UrlAndOPT} from '../../common/url-and-opt.enum';
import {IframePageComponent} from '../../components/iframe-page/iframe-page.component';

/**
 * 标的信息－借款详情
 */
@Component({
  selector: 'app-bid-detail',
  templateUrl: './bid-detail.page.html',
  styleUrls: ['./bid-detail.page.scss'],
})
export class BidDetailPage extends BasePage implements OnInit {

  bidInfo: any = {};
  bidItemSupervisor: any[] = [];

  constructor(public navCtrl: NavController,
              public toastCtrl: ToastController,
              private routeInfo: ActivatedRoute,
              private service$: HttpService,
              private modalCtrl: ModalController,
              private popoverCtrl: PopoverController
  ) {
    super(navCtrl, toastCtrl);
  }

  ngOnInit() {
    // 初始化数据
    this.getData(this.routeInfo.snapshot.params['bidIdSign']);
  }

  // 获取标的数据
  private getData(bidIdSign: string) {
    this.service$.doRequest(UrlAndOPT.bid_detail, {bidIdSign: bidIdSign})
      .subscribe(obj => {
        if (obj) {
          this.bidInfo = obj['bidInfo'];
          this.bidItemSupervisor = obj['bidItemSupervisor'];
        }
      });
  }

  // 查看认证资料
  async presentPopover(name, url: string) {
    if (url) {
      // const popover = await this.popoverCtrl.create({
      //   component: BidItemComponent,
      //   componentProps: {
      //     image_url: this.HOST + url
      //   }
      // });
      // await popover.present();
      const modal = await this.modalCtrl.create({
        component: BidItemComponent,
        componentProps: {
          title: name,
          image_url: this.HOST + url
        }
      });
      await modal.present();
    } else {
      await this.showToast('没有相关资料');
    }
  }

}
